package org.concepts.algorithm.datastructure;

import org.concepts.algorithm.datastructure.TreeUtils.Traversal;
import org.junit.Test;

public class TestTreeUtils {

  @Test
  public void testBreadthFirstTraversal() {
    TreeUtils.breadthFirstTraversal(getNode());
  }

  @Test
  public void testDepthFirstTraversal() {
    System.out.println("Pre order traversal");
    TreeUtils.depthFirstTraversal(getNode(), Traversal.PREORDER);
    
    System.out.println("Post order traversal");
    TreeUtils.depthFirstTraversal(getNode(), Traversal.POSTORDER);

    System.out.println("In order traversal");
    TreeUtils.depthFirstTraversal(getNode(), Traversal.INORDER);
    
    
  }

  private void printNode() {
    System.out.println("\n" +
        "\t\t\t\t\t0" + "\n" +
        "\t\t\t1.1" + "\t\t\t\t\t" + "1.2" + "\n" +
        "\t1.1.1\t\t\t1.1.2\t\t\t1.2.1\t\t1.2.2" + "\n" +
        "  1.1.1.1\t1.1.1.2\n"
        );
  }
  
  private SimpleNode<String> getNode() {
    SimpleNode<String> root = new SimpleNode<String>("0");

    root.addChild(new SimpleNode<String>("1.1"));
    root.getChildren().get(0).addChild(new SimpleNode<String>("1.1.1"));
    root.getChildren().get(0).getChildren().get(0).addChild(
        new SimpleNode<String>("1.1.1.1"));
    root.getChildren().get(0).getChildren().get(0).addChild(
        new SimpleNode<String>("1.1.1.2"));
    root.getChildren().get(0).addChild(new SimpleNode<String>("1.1.2"));

    root.addChild(new SimpleNode<String>("1.2"));
    root.getChildren().get(1).addChild(new SimpleNode<String>("1.2.1"));
    root.getChildren().get(1).addChild(new SimpleNode<String>("1.2.2"));
    printNode();
    return root;
  }

}
